home *** CD-ROM | disk | FTP | other *** search
- Path: gidora.kralizec.net.au!root
- From: rosko@zeta.org.au (Ross McKay)
- Newsgroups: comp.lang.c++
- Subject: Re: Code Base 5.1 problem
- Date: Sun, 04 Feb 1996 09:53:13 GMT
- Organization: Soft Technologies
- Message-ID: <4f1sib$2l1@gidora.kralizec.net.au>
- References: <4eufsf$908@granite.sentex.net>
- Reply-To: rosko@zeta.org.au
- NNTP-Posting-Host: dialup48.syd1.zeta.org.au
- X-Newsreader: Forte Free Agent 1.0.82
-
- mvejvoda@sentex.net (Mark Vejvoda) wrote:
-
- >I am writing my own DLL and I'm tryin to link in a codebase 5.1 static
- >library (as per instructions in the COMPILER.DOC) in Borlandc C++
- >4.02. In my D4ALL.H header i've declated some global vars to be used
- >in each .C module that i write. When i include d4all.h in these .C
- >modules the compile works.. but the linker says that the global
- >variables have been duplicated in each subsequent .C module. Why is
- >this.. what have i done wrong?
-
- Hi Mark, what you have done by "declaring" your global variables in
- your .h file is actually to *define* them there.
-
- The difference between declaring and defining globals is that
- declaring tells the compiler that they exist, and what type they are,
- whereas defining them tells the compiler to "create an instance" of
- them.
-
- e.g. of declaring (this tells compiler there WILL BE a foobar):
-
- extern int foobar;
-
- e.g. of defining (this tells compiler to MAKE a foobar):
-
- int foobar;
-
- You should declare your global variables ONCE in your .h file, and
- then all source files that include this .h file will know about your
- global variables.
-
- You should define your global variables ONCE in ONLY ONE of your
- source files, i.e. one .c or .cpp (or .cxx or .C or .foobar ;-)
- It is quite common (even recommended) practice to define all globals
- most related to a module in that module, or even have one source file
- specifically for globals (e.g. global.c)
-
- Regards,
- ------------------------------------------------------------------
- Ross McKay | snail: GPO Box 562, Sydney NSW 2001 Australia
- Soft Technologies | email: mailto:rosko@zeta.org.au
- Sydney, Australia | URL: http://www.zeta.org.au/~rosko
- ------------------------------------------------------------------
- The opinions expressed are my own, not those of Soft Technologies.
- "The beatings will continue, until staff morale improves."
-
-